/**
 * [一句话描述该类的功能]
 *
 * @author : [kai]
 * @version : [v1.0]
 * @createTime : [2022/10/25 13:55]
 */


package com.find.service.lmpl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.find.dao.ForumDao;
import com.find.domain.Forum;
import com.find.service.ForumService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class ForumServiceImpl extends ServiceImpl<ForumDao, Forum> implements ForumService {

    @Autowired
    private ForumDao forumDao;

    @Override
    public IPage<Forum> getPage(int currentPage, int pageSize) {
        IPage page = new Page(currentPage,pageSize);
        forumDao.selectPage(page,null);
        return page;
    }

    @Override
    public IPage<Forum> getMapPage(Map<String, Object> map, int currentPage, int pageSize) {
        QueryWrapper<Forum> lqw = new QueryWrapper<Forum>();
        for(Map.Entry<String,Object> entry:map.entrySet()){
            if("forum_des".equals(entry.getKey())||"forum_title".equals(entry.getKey())) {
                lqw.like(entry.getKey(), entry.getValue());
            }else{
                lqw.eq(entry.getKey(),entry.getValue());
            }
        }
        lqw.orderByDesc("forum_time");
        IPage page=new Page(currentPage,pageSize);
        forumDao.selectPage(page,lqw);
        return page;
    }
    @Override
    public IPage<Forum> getWordPage(String word,int type, int currentPage, int pageSize) {
        QueryWrapper<Forum> lqw = new QueryWrapper<Forum>();
        lqw.like("forum_title",word);
        if(type==1||type==0){lqw.and(l->l.eq("forum_type",type));}
        lqw.or().like("forum_des",word);
        if(type==1||type==0){lqw.and(l->l.eq("forum_type",type));}
        lqw.orderByDesc("forum_time");
        IPage page=new Page(currentPage,pageSize);
        forumDao.selectPage(page,lqw);
        return page;
    }
    @Override
    public List<Forum> myListByMap(Map<String,Object> map){
        QueryWrapper<Forum> lqw = new QueryWrapper<Forum>();
        int currentPage=0,pageSize=0;
        for(Map.Entry<String,Object> entry:map.entrySet()) {
            if ("forum_des".equals(entry.getKey()) || "forum_title".equals(entry.getKey())) {
                lqw.like(entry.getKey(), entry.getValue());
            } else {
                lqw.eq(entry.getKey(), entry.getValue());
            }
        }
        lqw.orderByDesc("forum_time");
        return forumDao.selectList(lqw);
    }
}
